using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class Ui_popup_Fold : Ui_popup
{
    public FlodDirection foldDir;
    private float time = 1.5f;

    private Vector2 closeedPos;
    private Vector2 openedPos;
    private Vector2 moveDir;

    Tweener tweener; //声明一个Tweener对象

    public override void Init()
    {
        base.Init();
        openedPos = rect.anchoredPosition;

        if (foldDir == FlodDirection.Left)
            moveDir = new Vector2(-1, 0);
        else if (foldDir == FlodDirection.Right)
            moveDir = new Vector2(1, 0);
        else if (foldDir == FlodDirection.Up)
            moveDir = new Vector2(0, 1);
        else if (foldDir == FlodDirection.Down)
            moveDir = new Vector2(0, -1);

        closeedPos = openedPos + moveDir * rect.rect.width;
    }

    public override void PopUp()
    {
        if (null != tweener && tweener.IsPlaying())
            tweener.Kill(false);

        tweener = transform.DOLocalMove(openedPos, time);
    }

    public override void Hide()
    {
        if (null != tweener && tweener.IsPlaying())
            tweener.Kill(false);
        tweener = transform.DOLocalMove(closeedPos, time);
    }
}

public enum FlodDirection
{
    Left,
    Right,
    Up,
    Down,
}
